#define _CRT_SECURE_NO_WARNINGS 1
#include"ProgressBar.h"
const char* str = "-\\|/";
void process_v1()
{
    char bar[SIZE] = { 0 };
    int rate = 0;
    int str_len = strlen(str);
    while (rate <= MAX_RATE)
    {
        printf("[%-100s][%d%%][%c]\r", bar, rate, str[rate % str_len]);
        bar[rate++] = STYLE;
    }
}
void process_v2(double rate)
{
      static char bar[SIZE] = { 0 };
      static int cnt = 0;
      if (rate >= 0 && rate <= MAX_RATE)
      {
          cnt = cnt > 4 ? 0 : cnt;
          printf("[%-100s][%.1f%][%c]\r", bar, rate, str[cnt++]);
          bar[(int)rate] = STYLE;
      }
      if (rate == MAX_RATE)
      {
        memset(bar, '\0', sizeof(bar));
        }
    }

void download(callback_t cb)
{
    int rate = 0;
    while (rate <= TARGET_SIZE)
    {
        //usleep(STIME);
        rate += DSIZE;
        cb(rate * 100.0 / TARGET_SIZE);
        rate += DSIZE;
    }
    cb((double)MAX_RATE);
    printf("\n");
}

